<template>
  <div class="box">
    <div class="box2">
      <i class="iconfont icon-404" />
      <i class="iconfont icon-icon-test" />
      <span class="text">
        {{ num }}秒后回到
        <router-link to="/home">首页</router-link>
      </span>
    </div>
  </div>
</template>

<script setup  name='NotFount'>
import { ref, onMounted, onBeforeUnmount } from 'vue'
import { useRouter } from 'vue-router'

// 声明变量
const num = ref(5)
const timer = ref(null)
const router = useRouter()

// 开启定时器
onMounted(() => {
  timer.value = setInterval(() => {
    if (num.value === 1) {
      clearInterval(timer.value)
      router.push('/home')
    }
    return num.value--
  }, 1000)
})

// 注销定时器
onBeforeUnmount(() => {
  clearInterval(timer.value)
})
</script>

<style lang="less" scoped>
.box {
  display: flex;
  width: 100%;
  height: 100vh;
  justify-content: center;
  align-items: center;
  .box2 {
    width: 320px;
    height: 500px;
    position: relative;
    line-height: 500px;
    i.icon-404 {
      color: #eeb422;
      font-size: 100px;
    }
    i.icon-icon-test {
      position: absolute;
      top: -180px;
      left: 180px;
      color: #b8860b;
      font-size: 100px;
    }
    span.text {
      width: 100%;
      height: 50px;
      line-height: 50px;
      text-align: center;
      position: absolute;
      bottom: 50px;
      left: 50%;
      transform: translate(-50%, 0);
      font-size: 20px;
    }
  }
}
</style>
